console.log('script start');

setTimeout(() => {
  console.log('背个');
}, 1 * 2000);

Promise.resolve().then(() => {
  console.log('promise1');
}).then(() => {
  console.log('promise2');
});

async function foo() {
  await bar();
  console.log('async1 end');
}
foo();

async function errorFunc() {
  try {
    await Promise.reject('error !!')
  } catch (e) {
    console.log(e);
  }
  console.log('async1');
  return Promise.resolve('async1 success');
}

errorFunc().then(res => console.log(res))

function bar() {
  console.log('async2 end');
}

console.log('script end');

// 宏任务：['背个']
// 微任务：['promise1', 'async1 end', 'error !!', 'async1', 'async1 success', 'promise2', 'async1 success']

// script start, async2 end, script end, promise1, async1 end, error !!, async1, async1 success, promise2, async1 success, 背个